<template>
  <base-layout
    :dialog-title="dialogTitle"
    :dialog-visible="dialogVisible"
    @dialog-close="dialogClose"
  >
    <template #searchPanel>
      <search-panel
        :addPer="'checkStorage:save'"
        :selectPer="'checkStorage:page'"
        addTitle="新增盘点单"
        @insert="add"
        @search="search"
        :showSearchButton="true"
        :showAddButton="true"
      >
        <Job-shop v-model="form.storeId" placeholder="所属门店" />
        <el-select
          clearable
          style="width: 200px"
          v-model="form.status"
          placeholder="状态"
        >
          <el-option
            v-for="item in dict['盘点状态']"
            :key="item.index"
            :value="item.value"
            :label="item.text"
          />
        </el-select>
        <el-input
          v-model="form.code"
          clearable
          placeholder="盘点单号"
          style="width: 200px"
        />
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :width="160"
        @row-dblclick="view"
      >
        <template #action="{ row }">
          <i
            class="el-icon-edit"
            title="编辑"
            style="cursor: pointer"
            v-permission="'checkStorage:update'"
            @click="handleDataUpdateEdit(row, '编辑')"
          ></i>
          <i
            class="el-icon-delete"
            title="删除"
            style="color: red; margin-left: 20px; cursor: pointer"
            v-permission="'checkStorage:del'"
            @click="handleDataUpdateEdit(row)"
          ></i>
        </template>
      </data-table>
    </template>
    <template #dialog>
      <dialog-view-detail :id="viewId" />
    </template>
  </base-layout>
</template>
<script>
import baseMixin from "@/mixins/base";
import { getDict } from "@/utils";
import { page, deleteById } from "@/api/after-sale/storehouseManage/inventoryCheck";
import { findByStore } from "@/api/after-sale/storehouseManage/warehouseManage";
import DialogViewDetail from "./view/index.vue";
export default {
  components: {
    DialogViewDetail,
  },
  mixins: [
    baseMixin({
      idName: "id",
      findData: page,
      dataName: ["content", "totalRecords"],
      format(res) {
        return res.map((data) => {
          data.preferred = data.preferred == true ? "是" : "否";
          data.openRestsStoreName = data.openRestsStore == true ? "启用" : "禁用";

          return data;
        });
      },
      deleteData: deleteById,
    }),
  ],
  data() {
    return {
      tableColumnAttributes: [
        { name: "盘点门店", value: "storeName", type: "text" },
        { name: "盘点单号", value: "code", type: "text" },
        { name: "单据日期", value: "receiptsTime", type: "text" },
        { name: "盘点任务名", value: "name", type: "text" },
        { name: "盘点仓库", value: "storageName", type: "text" },
        { name: "仓库编号", value: "storageCode", type: "text" },
        { name: "盘点配件", value: "checkNumber", type: "text" },
        { name: "配件总金额", value: "amount", type: "text" },
        { name: "盘点负责人", value: "userName", type: "text" },
        { name: "负责人联系方式", value: "phone", type: "text" },
        { name: "状态", value: "status", type: "text" },
        { name: "盘盈数量", value: "checkSurplusNumber", type: "text" },
        { name: "盘亏数量", value: "checkLoseNumber", type: "text" },
        { name: "正常数量", value: "checkNumber", type: "text" },
        { name: "备注", value: "remark", type: "text" },
      ],
      dict: [],
      dialogVisible: false,
      storageList: [],
      form: {
        storeId: "",
      },
    };
  },
  watch: {},
  methods: {
    add() {
      this.$router.push({ path: "/partsStock/partsStockManage/addInventoryCheck" });
    },
    handleDataUpdateEdit(row, type) {
      this.$router.push({
        path: "/partsStock/partsStockManage/editInventoryCheck",
        query: {
          id: row.id,
        },
      });
    },
    search(form) {
      this.searchOptions = this.form;
      this.currentPage = 1;
      this.setTableData();
    },
    // 查看入库
    view(row) {
      this.viewId = row.id;
      this.handleDataInsert("盘点详情");
    },
  },
  mounted() {
    this.dict = getDict(["盘点状态"]);
  },
};
</script>
